package com.example.movieratingbackend.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class Movie {

    private Long id;

    private String title;
    private List<String> genres;

    private String year;
    private String director;
    private String actors;
    private String plot;
    private String posterUrl;

    private Double averageRating;


    private List<Integer> ratings = new ArrayList<>();

    public Movie(Long id, String title, List<Integer> ratings) {
        this.id = id;
        this.title = title;
        this.ratings = ratings;
    }
    public Movie(String title) {

        this.title = title;

    }

    public void addRating(int rating) {
        this.ratings.add(rating);
        averageRating = ratings.stream().mapToInt(val -> val).average().orElse(0.0);
    }

}

